<div class="content-wrapper">

    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>

        <h1 class="pull-right">
            <?php echo $this->HelpUrl('orderList'); ?>
        </h1>

    </section>

    <section class="content">
        <?php echo $this->partial('layout/messages'); ?>
        <div class="row">
            <div class="col-xs-12">
                <div class="box shop-box">

                    <div class="box-body table-responsive no-padding">
                        <table class="table shop-table table-hover">
                            <thead>
                            <tr class="shop-bg-thead">
                                <!--th width="2%"><input type="checkbox" class="minimal select-all-checkbox"></th-->
                                <th width="25%"><?php echo $this->translate('订单编号'); ?></th>
                                <th width="12%"><?php echo $this->translate('买家'); ?></th>
                                <th width="10%"><?php echo $this->translate('状态'); ?></th>
                                <th width="8%"><?php echo $this->translate('金额'); ?></th>
                                <th width="10%"><?php echo $this->translate('配送类型'); ?></th>
                                <th width="15%"><?php echo $this->translate('下单时间'); ?></th>
                                <th width="18%"><?php echo $this->translate('操作'); ?></th>
                            </tr>
                            <?php
                            $sForm = $this->searchForm;
                            $sForm->prepare();
                            $sForm->get('order_status')->setEmptyOption('状态');
                            $sForm->get('delivery_type')->setEmptyOption('选择');
                            ?>
                            <?php echo $this->form()->openTag($sForm); ?>
                            <tr>
                                <!--td></td-->
                                <td>
                                    <?php echo $this->formElement($sForm->get('order_sn')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('order_sn'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('user_name')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('user_name'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('order_status')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('order_status'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('order_amount')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('order_amount'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('delivery_type')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('delivery_type'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <p>
                                        <?php echo $this->formElement($sForm->get('start_time')); ?>
                                    </p>
                                    <div>
                                        <?php echo $this->formElement($sForm->get('end_time')); ?>
                                    </div>
                                    <?php echo $this->formElementErrors($sForm->get('start_time'), ['class'=>'error-message']);?>
                                    <?php echo $this->formElementErrors($sForm->get('end_time'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <button type="submit" class="btn btn-info btn-sm"><i class="fa fa-search"></i></button>
                                    <?php
                                    $formData = array_filter($sForm->getData());
                                    if(!empty($formData) || (isset($formData['order_status']) && $formData['order_status'] != '')) { ?>
                                        &nbsp;&nbsp;<a href="<?php echo $this->url('sales');?>" class="btn btn-default btn-sm"><i class="fa fa-reply"></i></a>
                                    <?php } $formData['page'] = $this->orderList->getCurrentPageNumber(); ?>
                                </td>
                            </tr>
                            <?php echo $this->form()->closeTag(); ?>
                            </thead>
                            <tbody>
                            <?php if($this->orderList->getCurrentItemCount() > 0) foreach ($this->orderList as $orderValue) { ?>
                                <tr>
                                    <!--td><input name="select_id[]" value="<?php echo $orderValue->getOrderId(); ?>" type="checkbox" ></td-->
                                    <td>
                                        <?php echo $orderValue->getOrderSn(); ?>
                                        <p>
                                            <?php foreach($orderValue->getOrderGoods() as $goodsValue) { ?>
                                                <img src="<?php echo $this->goodsHelper()->goodsImage($goodsValue->getGoodsImage()); ?>" title="<?php echo $this->escapeHtml($goodsValue->getGoodsName().(!empty($goodsValue->getInSpecGoodsStr()) ? '  '.$goodsValue->getInSpecGoodsStr() : '')); ?>" alt="<?php echo $this->escapeHtml($goodsValue->getGoodsName().'&nbsp;&nbsp;'.$goodsValue->getInSpecGoodsStr()); ?>" class="img-thumbnail" style="width: 40px;height: 40px;">
                                            <?php } ?>
                                        </p>
                                    </td>
                                    <td><?php echo $this->escapeHtml($orderValue->getUserName()); ?></td>
                                    <td><?php echo $this->salesHelper()->getOrderStatus($orderValue->getOrderStatus()); ?></td>
                                    <td><?php echo $this->shopCurrencyFormat($orderValue->getOrderAmount(), null, $orderValue->getCurrencyCode()); ?></td>
                                    <td><?php echo $this->salesHelper()->getDeliveryTypeName($orderValue->getDeliveryType()); ?></td>
                                    <td><?php echo $this->shopDateFormat()->orderTime($orderValue->getOrderAddTime()); ?></td>
                                    <td>
                                        <a href="<?php echo $this->url('sales',
                                            ['action'=>'detail', 'id'=>$orderValue->getOrderId()], ['query' => $formData]); ?>"
                                           class="btn btn-xs btn-success"><i class="fa fa-info-circle"></i> <?php echo $this->translate('详情'); ?></a>

                                        <?php if($orderValue->getOrderStatus() >= $this->salesHelper()->getOrderStatusCode('WAIT_PAYMENT') && $orderValue->getOrderStatus() < $this->salesHelper()->getOrderStatusCode('GOODS_RECEIVED')) { ?>
                                        <div class="btn-group">
                                            <button type="button" class="btn btn-xs btn-success dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?php echo $this->translate('更多'); ?> <span class="caret"></span></button>
                                            <ul class="dropdown-menu">
                                                <?php
                                                if(
                                                    $orderValue->getOrderStatus() > $this->salesHelper()->getOrderStatusCode('CANCEL_ORDER')
                                                    && (
                                                        ($orderValue->getPaymentType() == 'OnlinePay' && $orderValue->getOrderStatus() < $this->salesHelper()->getOrderStatusCode('WAIT_GOODS_ARRIVE'))
                                                        || ($orderValue->getPaymentType() == 'CashOnDelivery' && $orderValue->getOrderStatus() <= $this->salesHelper()->getOrderStatusCode('FINISH_DISTRIBUTION_GOODS'))
                                                    )
                                                ) { ?>
                                                    <li><a href="<?php echo $this->url('sales', ['action'=>'cancelOrder', 'id'=>$orderValue->getOrderId()], ['query' => $formData]); ?>"><small><?php echo $this->translate('取消订单'); ?></small></a></li>
                                                <?php } ?>
                                                <?php if($orderValue->getOrderStatus() == $this->salesHelper()->getOrderStatusCode('wait_payment') && $orderValue->getPaymentType() != 'CashOnDelivery') { ?>
                                                    <li><a href="<?php echo $this->url('sales', ['action'=>'payOrder', 'id'=>$orderValue->getOrderId()], ['query' => $formData]); ?>"><small><?php echo $this->translate('订单付款'); ?></small></a></li>
                                                <?php } ?>
                                                <?php if(
                                                        $orderValue->getDeliveryType() != 'selfFetch'
                                                        && (
                                                                ($orderValue->getOrderStatus() >= $this->salesHelper()->getOrderStatusCode('wait_payment') && $orderValue->getOrderStatus() <= $this->salesHelper()->getOrderStatusCode('finish_distribution_goods') && $orderValue->getPaymentType() == 'CashOnDelivery')
                                                                || ($orderValue->getOrderStatus() > $this->salesHelper()->getOrderStatusCode('wait_payment') && $orderValue->getOrderStatus() <= $this->salesHelper()->getOrderStatusCode('finish_distribution_goods') && $orderValue->getPaymentType() != 'CashOnDelivery')
                                                            )
                                                        ) { ?>
                                                    <li><a href="<?php echo $this->url('sales', ['action' => ($orderValue->getDeliveryType() == 'autoDelivery' ? 'sendOrderGoodsVirtual' : 'shipOrder'), 'id'=>$orderValue->getOrderId()], ['query' => $formData]); ?>"><small><?php echo $this->translate('订单发货'); ?></small></a></li>
                                                <?php } ?>
                                                <?php if(
                                                        ($orderValue->getOrderStatus() >= $this->salesHelper()->getOrderStatusCode('GOODS_SHIPPED') || ($orderValue->getOrderStatus() > $this->salesHelper()->getOrderStatusCode('wait_payment') && $orderValue->getDeliveryType() == 'selfFetch'))
                                                        && $orderValue->getOrderStatus() < $this->salesHelper()->getOrderStatusCode('GOODS_RECEIVED')
                                                        ) { ?>
                                                    <?php
                                                    if (
                                                            $orderValue->getDeliveryType() == 'delivery'
                                                            && $this->shopHelper()->getDeliveryTrackState() == 1
                                                            && (
                                                                    ($orderValue->getDeliveryId() > 0 && !empty($this->deliveryIdArray) && isset($this->deliveryIdArray[$orderValue->getDeliveryId()]))
                                                                    || $orderValue->getDeliveryId() <= 0
                                                                )
                                                        ) { ?>
                                                        <li><a href="<?php echo $this->url('sales', ['action'=>'showOrderExpressTrack', 'id'=>$orderValue->getOrderId()], ['query' => $formData]); ?>"><small><?php echo $this->translate('物流轨迹'); ?></small></a></li>
                                                    <?php } ?>
                                                    <li><a href="<?php echo $this->url('sales', ['action'=>'receiptOrder', 'id'=>$orderValue->getOrderId()], ['query' => $formData]); ?>"><small><?php echo $this->translate('订单收货'); ?></small></a></li>
                                                <?php } ?>
                                            </ul>
                                        </div>
                                        <?php } ?>

                                        <a href="<?php echo $this->url('sales', ['action'=>'printOrder', 'id'=>$orderValue->getOrderId()], ['query' => $formData]); ?>" class="btn btn-xs btn-primary"><i class="fa fa-print"></i> <?php echo $this->translate('打印'); ?></a>

                                        <?php if($orderValue->getOrderStatus() == $this->salesHelper()->getOrderStatusCode('CANCEL_ORDER')) { ?>
                                            <a href="javascript:;" onclick="deleteConfirm('<?php echo $this->translate('您确实要删除该订单吗?'); ?>', '<?php echo $this->url('sales', ['action'=>'delete', 'id'=>$orderValue->getOrderId()], ['query' => ['qToken' => $this->adminHelper()->getCsrfValue()]]); ?>');" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i> <?php echo $this->translate('删除'); ?></a>
                                        <?php } ?>
                                    </td>
                                </tr>
                            <?php } ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="box-footer clearfix">
                        <!--div class="pull-left">
                            <input type="checkbox" class="minimal select-all-checkbox"> <?php echo $this->translate('全选'); ?>
                            <select name="editAllState">
                                <option value=""><?php echo $this->translate('选择状态'); ?></option>
                                <option value="cancelOrder"><?php echo $this->translate('取消'); ?></option>
                                <option value="deleteOrder"><?php echo $this->translate('删除'); ?></option>
                            </select>
                            <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> <?php echo $this->translate('更新'); ?></button>
                        </div-->
                        <?php echo $this->paginationControl($this->orderList, 'Sliding', 'layout/page', ['route' => 'sales']); ?>
                    </div>
                </div>

            </div>
        </div>

    </section>
</div>
<script>
    laydate.render({elem: '#start_time'});
    laydate.render({elem: '#end_time'});
</script>